<template>
  <div class="app-container">
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="操作 1- 充值 2 消费" prop="operation">-->
<!--        <el-input-->
<!--          v-model="queryParams.operation"-->
<!--          placeholder="请输入操作 1- 充值 2 消费"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="企业名称" prop="contractName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入企业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="deal_recordList" border stripe>
      <el-table-column label="编号" align="center" prop="id" v-if="false"/>
      <el-table-column prop="companyName" label="所属企业" header-align="center" />
      <el-table-column label="合同名称" align="center" prop="contractName" header-align="center"/>
      <el-table-column prop="originalAmount" :label="$t('deal.originalAmount')" header-align="center" align="center" width="160">
        <template slot-scope="scope">
          <span>{{scope.row.originalAmount.toFixed(2)}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="rechargeAmount" :label="$t('deal.rechargeAmount')" header-align="center" align="center" width="160">
        <template slot-scope="scope">
          <span>{{scope.row.rechargeAmount.toFixed(2)}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="totalAmount" :label="$t('deal.totalAmount')" header-align="center" align="center" width="160">
        <template slot-scope="scope">
          <span v-if="scope.row.operation === 2">{{(scope.row.originalAmount- scope.row.rechargeAmount).toFixed(2)}}</span>
          <span v-else >{{(scope.row.originalAmount+scope.row.rechargeAmount).toFixed(2)}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="paymentType" :label="$t('deal.paymentType')" header-align="center" align="center" width="120">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.paymentType === 1" size="mini" >{{ $t('deal.paymentType1') }}</el-tag>
          <el-tag v-else-if="scope.row.paymentType === 2" size="mini" type="success">{{ $t('deal.paymentType2') }}</el-tag>
          <el-tag v-else-if="scope.row.paymentType === 3" size="mini" type="info">{{ $t('deal.paymentType3') }}</el-tag>
          <el-tag v-else-if="scope.row.paymentType === 4" size="mini" type="warning">{{ $t('deal.paymentType4') }}</el-tag>
          <el-tag v-else-if="scope.row.paymentType === 5" size="mini" type="warning">{{ $t('deal.paymentType5') }}</el-tag>
          <el-tag v-else-if="scope.row.paymentType === 6" size="mini" type="danger">{{ $t('deal.paymentType6') }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="operation" :label="$t('deal.operation')" header-align="center" align="center" width="120">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.operation === 2" size="mini" type="danger">{{ $t('deal.operation2') }}</el-tag>
          <el-tag v-else size="mini" type="success">{{ $t('deal.operation1') }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="remark" :label="$t('remark')" header-align="center" align="center"/>
      <el-table-column prop="createTime" :label="$t('role.createTime')" sortable="custom" header-align="center" align="center" width="180"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['DealRecord:deal_record:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['DealRecord:deal_record:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改交易记录(包含支付充值记录)对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="类型" prop="type">
          <el-select v-model="form.type" placeholder="请选择类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="状态 1-正常 0- 禁用">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="逻辑删除 0-删除, 默认-1" prop="valid">
          <el-input v-model="form.valid" placeholder="请输入逻辑删除 0-删除, 默认-1" />
        </el-form-item>
        <el-form-item label="账户id" prop="accountId">
          <el-input v-model="form.accountId" placeholder="请输入账户id" />
        </el-form-item>
        <el-form-item label="充值支付类型 1 - 支付宝, 2-微信, 3.现金, 4其它，5合同签署支付" prop="paymentType">
          <el-select v-model="form.paymentType" placeholder="请选择充值支付类型 1 - 支付宝, 2-微信, 3.现金, 4其它，5合同签署支付">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="充值前原始金额" prop="originalAmount">
          <el-input v-model="form.originalAmount" placeholder="请输入充值前原始金额" />
        </el-form-item>
        <el-form-item label="充值金额" prop="rechargeAmount">
          <el-input v-model="form.rechargeAmount" placeholder="请输入充值金额" />
        </el-form-item>
        <el-form-item label="额外金额(如充值赠送)" prop="extraAmount">
          <el-input v-model="form.extraAmount" placeholder="请输入额外金额(如充值赠送)" />
        </el-form-item>
        <el-form-item label="操作 1- 充值 2 消费" prop="operation">
          <el-input v-model="form.operation" placeholder="请输入操作 1- 充值 2 消费" />
        </el-form-item>
        <el-form-item label="合同名称" prop="contractName">
          <el-input v-model="form.contractName" placeholder="请输入合同名称" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
  </div>
</template>

<script>
import { listDeal_record, getDeal_record, delDeal_record, addDeal_record, updateDeal_record, exportDeal_record } from "@/api/zfw/dealRecord/deal_record";

export default {
  name: "Deal_record",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 交易记录(包含支付充值记录)表格数据
      deal_recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: undefined,
        status: undefined,
        valid: undefined,
        accountId: undefined,
        paymentType: undefined,
        originalAmount: undefined,
        rechargeAmount: undefined,
        extraAmount: undefined,
        operation: undefined,
        contractName: undefined,
        companyName: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询交易记录(包含支付充值记录)列表 */
    getList() {
      this.loading = true;
      listDeal_record(this.queryParams).then(response => {
        this.deal_recordList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        type: undefined,
        status: 0,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        valid: undefined,
        accountId: undefined,
        paymentType: undefined,
        originalAmount: undefined,
        rechargeAmount: undefined,
        extraAmount: undefined,
        operation: undefined,
        contractName: undefined,
        companyName:undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加交易记录(包含支付充值记录)";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDeal_record(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改交易记录(包含支付充值记录)";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDeal_record(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDeal_record(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除交易记录(包含支付充值记录)编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDeal_record(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有交易记录(包含支付充值记录)数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportDeal_record(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
